<?php

/**
 * 
 * Enter description here ...
 * @author crackerjack
 *
 */
class IndexController extends App_Controller_Base
{
	/**
	 * (non-PHPdoc)
	 * @see App_Controller_Base::init()
	 */
	public function init()
	{
		parent::init();
	}
	
	/**
	 * 
	 * Enter description here ...
	 */
	public function indexAction()
	{
		if(isset($this->_user->info['id'])){
			$this->render('home');
		} else {
			if(isset($this->_user->access_denied)){
				$this->view->assign('denied_message',$this->_user->access_denied);
			}	
			$this->render('index');
		}
		// debug($this->_user->info);
	}
	
	/**
	 * 
	 * Enter description here ...
	 */
	public function authAction()
	{
		$this->_helper->viewRenderer->setNoRender(true);
		$username = $this->_request->getPost('username');
		$password = $this->_request->getPost('password');
		if(has_value($username) || has_value($password)){
			$user = new App_Db_User();
			$user->setUsername($username);
			$user->setPassword($password);
			if($user->login()){
				$this->_user->info = $user->getLoginInfo();
				$userLog = new TechnoDK_LogFile(APP_DIR . '/logs/login.tcl');
				if($userLog->log($this->_user->info)){
					//$this->_user->setExpirationSeconds(300,'info');
					unset($this->_user->access_denied);
				}
			} else {
				$this->_user->access_denied = 'Invalid username and password';
			}
		} else {
			$this->_user->access_denied = 'Please enter your username and password';
		}
		$this->_redirect(HTTP_HOST);
	}
	
	/**
	 *
	 *
	 */
	public function logoutAction()
	{
		$this->_helper->viewRenderer->setNoRender(true);
		//$user = new App_Db_User();
		//if($user->logoutById($this->_user->info['id'])){
			unset($this->_user->info);
			$this->_redirect(HTTP_HOST);
		//}		
	}
	
}



?>